package com.qf.cx.simplenms.subscriber.model;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

import com.qf.cx.simplenms.topic.api.Topic;

public class SubscriberModel {

	private long id;
	private String url;
	private final Set<Topic> topics = new CopyOnWriteArraySet<>();

	public synchronized long getId() {
		return id;
	}

	public synchronized void setId(long id) {
		this.id = id;
	}

	public synchronized String getUrl() {
		return url;
	}

	public synchronized void setUrl(String url) {
		this.url = url;
	}

	public synchronized Set<Topic> getTopics() {
		return new HashSet<>(topics);
	}

	@Override
	public String toString() {
		return "SubscriberModel [id=" + id + ", url=" + url + "]";
	}

	public void deleteTopics(Set<Topic> deletes) {
		topics.removeAll(deletes);
	}

	public void addTopics(Set<Topic> adds) {
		topics.addAll(adds);
	}

	public boolean hasTopic() {
		return !topics.isEmpty();
	}
}
